﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Helena.Areas.Proveedores.Models;
using Telerik.Web.Mvc;
using Helena.Areas.Vendedores.Models;

namespace Helena.Areas.Proveedores.Controllers
{
    public class ProveedorController : Controller
    {
        //
        // GET: /Proveedores/Proveedor/

        LogicaProveedor db = new LogicaProveedor(); 
                
        public ActionResult Index()
        {
            VendedorView vw = (VendedorView)Session["Vendedor"];
            if (vw.ID != 0)
            {
                return View();
            }
            else
            {
                return Redirect("../Home/NoSession");
            }
        }

        [GridAction]
        public ActionResult Select()
        {
            return View("Index", new GridModel(db.i_RetornarProveedores()));
        }

        [AcceptVerbs(HttpVerbs.Post)]
        [GridAction]
        public ActionResult Insert()
        {

            ProveedorView p_v = new ProveedorView();
            if (TryUpdateModel(p_v))
            {
                db.i_AgregarProveedor(p_v);
            }
            return View("Index", new GridModel(db.i_RetornarProveedores()));
        }

        [AcceptVerbs(HttpVerbs.Post)]
        [GridAction]
        public ActionResult Delete(int? id)
        {
            int ID = id ?? -1;
            db.i_EliminarProveedor(ID);
            return View("Index", new GridModel(db.i_RetornarProveedores()));
        }

        [AcceptVerbs(HttpVerbs.Post)]
        [GridAction]
        public ActionResult Update(ProveedorView p_v)
        {
            db.i_ModificarProveedor(p_v);
            return View("Index", new GridModel(db.i_RetornarProveedores()));
        }
    }
}
